package com.topsec.erp.service.impl;

import com.topsec.erp.entity.User;
import com.topsec.erp.repository.UserRepository;
import com.topsec.erp.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author: zsl
 * date: 2019/11/22 11:13
 * Description:
 */
@Service
public class UserServiceImpl implements UserService {


	// 日志记录器
	private final Logger log = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private UserRepository userRepository;




	@Override
	public List<User> queryAll() {
		return userRepository.findAll();
	}

	@Override
	public User findById(long id) {
		return userRepository.findById(id).get();
	}

	@Override
	public List<User> findByUsername(String username) {
		return userRepository.findByNameLike("%"+username+"%");
	}

	@Override
	public void save(User user) {
		userRepository.save(user);
	}

	@Override
	public void delete(long id) {
		userRepository.deleteById(id);
	}

	@Override
	public void update(User user) {
		userRepository.save(user);
	}
}
